/* 
 * Length of Last Word
 * For example, Given s = "Hello World", return 5
 */

#include "../func.h"

int lengthOfLastWord(const string &s)
{
    auto first = find_if(s.rbegin(), s.rend(), ::isalpha);
    auto last = find_if(first, s.rend(), ::isalpha);
    return distance(first, last);
}

int lengthOfLastWord2(const char *s)
{
    int len = 0;
    while (*s)
    {
        if (*s++ != ' ')
            ++len;
        else if (*s && *s != ' ')
            len = 0;
    }
    return len;
}